from peewee import BigIntegerField, CharField, DateTimeField, DecimalField
from playhouse.mysql_ext import JSONField
from common.model.abstrct import AbstractModel


class AliPayTransaction(AbstractModel):

    class Meta:
        table_name = "tb_transaction"
        indexes = (
            (("tenant_id", "order_sn"), False),
            (("order_sn", ), False),
            (("transaction_id", ), True),
            (("buyer_user_id", ), False)
        )

    tenant_id = BigIntegerField(help_text="租户id")
    transaction_id = CharField(max_length=32, help_text="交易单号")
    order_sn = CharField(help_text="订单号")
    buyer_user_id = CharField(max_length=32, help_text="支付宝用户id")

    # 在沙箱环境下不管怎么弄都是0.0
    buyer_pay_amount = DecimalField(help_text="买家实付金额")
    total_amount = DecimalField(help_text="交易金额")
    receive_time = DateTimeField(help_text="支付宝提供的到账时间")
    trade_status = CharField(max_length=16, help_text="交易状态")
    snapshot = JSONField(help_text="接口原始数据")
